package com.mycjj.android.adapter;


import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.mycjj.android.R;
import com.mycjj.android.activity.CarNetworkFriendDetailActivity;
import com.mycjj.android.bean.CarNetworkThemesBean;

public class CarNetworkThemeAdapter extends TAdapter<CarNetworkThemesBean>{

	public CarNetworkThemeAdapter(Context mContext) {
		super(mContext);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_carnetwork_theme, null);
			holder = new ViewHolder();
			holder.iv_pic = (ImageView) convertView.findViewById(R.id.iv_pic);
			holder.tv_name = (TextView)convertView.findViewById(R.id.tv_name);
			holder.tv_carnetwork = (TextView)convertView.findViewById(R.id.tv_carnetwork);
			holder.tv_time = (TextView)convertView.findViewById(R.id.tv_time);
			holder.tv_title = (TextView)convertView.findViewById(R.id.tv_title);
			holder.tv_share = (TextView)convertView.findViewById(R.id.tv_share);
			holder.tv_comment = (TextView)convertView.findViewById(R.id.tv_comment);
			holder.tv_like = (TextView)convertView.findViewById(R.id.tv_like);
			holder.tv_top = (TextView)convertView.findViewById(R.id.tv_top);
			holder.tv_good = (TextView)convertView.findViewById(R.id.tv_good);
			holder.tv_recommend = (TextView)convertView.findViewById(R.id.tv_recommend);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		
		final CarNetworkThemesBean bean = mList.get(position);
		
//		imageLoader.displayImage(bean.getAuthor_avatar(), holder.iv_pic);
		imageLoader1.displayImage(bean.getAuthor_avatar(), holder.iv_pic,options,animateFirstListener);
		holder.tv_name.setText(bean.getAuthor_name());
		holder.tv_carnetwork.setText(bean.getCircle_name());
		holder.tv_time.setText(bean.getAddtime());
		holder.tv_title.setText(bean.getTheme_name());
		holder.tv_share.setText(bean.getShare_count());
		holder.tv_comment.setText(bean.getComment_count());
		holder.tv_like.setText(bean.getLike_count());
		if(bean.getIs_stick() == "1")
		{
			holder.tv_top.setVisibility(View.VISIBLE);
		}
		else if(bean.getIs_digest() == "1")
		{
			holder.tv_good.setVisibility(View.VISIBLE);
		}
		else if(bean.getIs_recommend() == "1")
		{
			holder.tv_recommend.setVisibility(View.VISIBLE);
		}
		
		holder.iv_pic.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext,CarNetworkFriendDetailActivity.class);
				intent.putExtra("id", bean.getAuthor_id());
				mContext.startActivity(intent);
			}
		});
		holder.tv_name.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext,CarNetworkFriendDetailActivity.class);
				intent.putExtra("id", bean.getAuthor_id());
				mContext.startActivity(intent);
			}
		});
		return convertView;
	}
	
	static class ViewHolder{
		ImageView iv_pic;
		TextView tv_name;
		TextView tv_carnetwork;
		TextView tv_time;
		TextView tv_title;
		TextView tv_share;
		TextView tv_comment;
		TextView tv_like;
		TextView tv_top;
		TextView tv_good;
		TextView tv_recommend;
	}
	
}
